package com.tpyule.tpclass.service.impl;

import com.tpyule.tpclass.dao.CommentDao;
import com.tpyule.tpclass.entity.bean.FailResultBean;
import com.tpyule.tpclass.entity.bean.ResultBean;
import com.tpyule.tpclass.entity.bean.SuccessResultBean;
import com.tpyule.tpclass.entity.bo.CommentDetailBo;
import com.tpyule.tpclass.entity.dto.CommentQueryDto;
import com.tpyule.tpclass.entity.pojo.Comment;
import com.tpyule.tpclass.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * @author zzz
 * @version 1.0
 * @date 2020/4/15 17:10
 */
@Service
public class CommentServiceImpl implements CommentService {
    @Autowired
    CommentDao commentDao;
    @Override
    public ResultBean addComment(Comment comment) {
        ResultBean resultBean=null;
        if(comment!=null){
            comment.setCommentId(UUID.randomUUID().toString().toUpperCase());
            int result = commentDao.addComment(comment);
            if(result!=0){
                resultBean=new SuccessResultBean(comment,"添加成功！");
            }else{
                resultBean = new FailResultBean("添加失败");
            }
        }else {
            resultBean = new FailResultBean("添加失败，评论数据有问题");
        }
        return resultBean;
    }

    @Override
    public ResultBean getListComment(CommentQueryDto commentQueryDto) {
        ResultBean resultBean = null;
        if(commentQueryDto != null){
            List<CommentDetailBo> comments = commentDao.getListComment(commentQueryDto);
            if(comments!=null){
                resultBean = new SuccessResultBean(comments,"获取成功");
            }else {
                resultBean = new FailResultBean("获取失败");
            }
        } else {
            resultBean = new FailResultBean("数据错误");
        }
        return resultBean;
    }
}
